MAINLIB = ~/csr-repository/lib/
#MAININC = ~/csr-repository/include/
CFLAGS_COMMON=-I$(HOME)/csr-repository/include
# FLAGS for opencv
# -fPIC necessary to allow proper construction of shared library
LDFLAGS_COMMON = -lstdc++ -lwiringPi



BUILD_TYPE=debug
#BUILD_TYPE=release

ifeq ($(BUILD_TYPE), debug)
	CFLAGS = -g $(CFLAGS_COMMON)
	LDFLAGS = $(LDFLAGS_COMMON)
endif
ifeq ($(BUILD_TYPE), release)
	# -O3 tells the compiler to optimize which takes more time, however the code is about 50% faster
	CFLAGS = $(CFLAGS_COMMON) -O3
	LDFLAGS = $(LDFLAGS_COMMON) -O3
endif

TARGETS= $(MAINLIB)/libperipherals.so

OFILES= Motor.o Bumper.o send.o #LED.o 

all: $(TARGETS)

Motor.o: Motor.cpp
	gcc -c Motor.cpp $(CFLAGS) -o $@

Bumper.o: Bumper.cpp
	gcc -c Bumper.cpp $(CFLAGS) -o $@

#LED.o: LED.cpp
#	gcc -c LED.cpp $(CFLAGS) -o $@

send.o: send.cpp
	gcc -c send.cpp $(CFLAGS) -o $@

$(MAINLIB)/libperipherals.so: $(OFILES)
	gcc -shared -o $(MAINLIB)/libperipherals.so $(LDFLAGS) $+



clean:	
	rm -f *.o
	rm -f *.d
